/**
 * Created by new on 2017/5/23.
 */
$(document).ready(function () {

    $.jgrid.defaults.styleUI = 'Bootstrap';

    $("#table_list_2").jqGrid({
        // data: mydata,
        url: '/admin/pipe/list',
        datatype: "json",
        editurl: '/admin/pipe/update',
        height: 425,
        autowidth: true,
        // align: "center",
        shrinkToFit: true,
        rowNum: 20,
        rowList: [10, 20, 30],
        colNames: ["序号","类型","走向","管线直径","起点埋深","终点埋深","起点地面高程","终点地面高程","起点井底高程","终点井底高程","长度"],
        colModel: [
            {name: 'id', index: 'id', editable: true, width: 15, sorttype: "int", search: true, align: "center",editoptions:{readonly:true}},
            {name: 'types', index: 'types', editable: true, width: 20, align: "center"},
            {name: 'towards', index: 'towards', editable: true, width: 35, align: "center", sorttype: "float",editrules:{required:true}},
            {name: 'pipeDiameter', index: 'pipeDiameter', editable: true, width: 30, align: "center", sorttype: "float",editrules:{required:true}},
            {name: 'startDeep', index: 'startDeep', editable: true, width: 40, align: "center", sorttype: "float",editrules:{required:true}},
            {name: 'endDeep', index: 'endDeep', editable: true, align: "center", width:40, sortable: false, sorttype: "float",editrules:{required:true}},
            {name: 'startGroundElevation', index: 'startGroundElevation', editable: true, width: 50, align: "center", sorttype: "float",editrules:{required:true}},
            {name: 'endGroundElevation', index: 'endGroundElevation', editable: true, width: 40, align: "center", sorttype: "float",editrules:{required:true}},
            {name: 'startWellElevation', index: 'startWellElevation', editable: true, width: 40, align: "center", sorttype: "float",editrules:{required:true}},
            {name: 'endWellElevation', index: 'endWellElevation', editable: true, width: 40, align: "center", sorttype: "float",editrules:{required:true}},
            {name: 'lengths', index: 'lengths', editable: true, width: 40, align: "center", sorttype: "float"}
        ],
        pager: "#pager_list_2",
        viewrecords: true,
        caption: "地下管道数据",
        add: true,
        edit: true,
        addtext: 'Add',
        edittext: 'Edit',
        hidegrid: false,
        jsonReader: {
            root: "data.list",
            page: "data.currPage",
            total: "data.totalPage",
            records: "data.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        }
    });

    // Add selection
    $("#table_list_2").setSelection(4, true);


    // Setup buttons
    $("#table_list_2").jqGrid('navGrid', '#pager_list_2', {
        edit: true,
        add: true,
        del: true,
        search: true
    }, {
        height: 200,
        reloadAfterSubmit: true
    },{
        url: '/admin/pipe/save',
        closeAfterAdd: true
    },{
        url: '/admin/pipe/delete',
        closeAfterDelete: true
    },{
        url: '/admin/pipe/search',
        closeAfterSearch: true
    });

    // Add responsive to jqGrid
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list_2').setGridWidth(width);
    });
});